﻿using UnityEngine;
using System.Collections;

public class Chosen : MonoBehaviour
{
	
	MouseOrbitImproved cameraScript;
	
	void Start ()
	{
		cameraScript = Camera.main.GetComponent<MouseOrbitImproved> ();
	}

	void OnDrag ()
	{
		cameraScript.OnDrag ();
	}

	void OnScroll ()
	{
		cameraScript.OnScroll ();
	}

	public void OnDoubleClick ()
	{
		if (transform.parent != null) {
			transform.parent.gameObject.GetComponent<Chosen>().OnClick();
			Destroy (gameObject);
		}
	}

	public void OnClick ()
	{
		//Because DragItem.cs calls this before Start is executed
		if (cameraScript == null)
			cameraScript = Camera.main.GetComponent<MouseOrbitImproved> ();

		//Use Lerp on the following two transform changes
		cameraScript.changeTarget (transform);
		GameObject.FindGameObjectWithTag ("Cube Frame").transform.position = transform.position;
		GameObject.FindGameObjectWithTag ("Cube Frame").transform.parent = transform;
	}
}
